<!doctype html>
<html>
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="initial-scale=1.0, user-scalable=no, width=device-width">
    <meta name="key" content="2e4297fe4871c95fb4b7b6c0d32a6685">
    <title>map</title>
    <link rel="stylesheet" href="http://cache.amap.com/lbs/static/main1119.css"/>
    <script src="http://cache.amap.com/lbs/static/es5.min.js"></script>
    <script src="http://webapi.amap.com/maps?v=1.3&key="></script>
    <script type="text/javascript" src="http://cache.amap.com/lbs/static/addToolbar.js"></script>
</head>
<body>
<div id="container"></div>

<script>
    var map = new AMap.Map('container', {
        resizeEnable: true,
        zoom:11,
        center: ['<%= data.lon %>', '<%= data.lat %>']
        
    });
	var marker = new AMap.Marker({
            map: map,
            position: ['<%= data.lon %>', '<%= data.lat %>']
        });
  var infoWindow = new AMap.InfoWindow({
        isCustom: true,  //使用自定义窗体
        content: '<div style="background:rgba(0,0,0,.3);color:#ffffff;">试一下</div>',
        offset: new AMap.Pixel(16, -45)
    });
  infoWindow.open(map, marker.getPosition());
var getGeolocation = function (cb) {
		var timeout, timeoutHandle;
		if(navigator.geolocation){
			navigator.geolocation.getCurrentPosition(function(position){
				var pos = {
					lat: position.coords.latitude,
					lon: position.coords.longitude
				};
				if(!timeout){
					cb(null, pos);
					if(timeoutHandle){
						clearTimeout(timeoutHandle);
						timeoutHandle = null;
					}
				}
			}, function(error){
				var errors = {
						1: 'Authorization fails', // permission denied
						2: 'Can\'t detect your location', //position unavailable
						3: 'Connection timeout' // timeout
				};
				if(!timeout){
					cb({code: error.code, message: errors[error.code]});
					if(timeoutHandle){
						clearTimeout(timeoutHandle);
						timeoutHandle = null;
					}
				}
			}, {
				enableHighAccuray: false	
			});	
			timeoutHandle = setTimeout(function(){
				cb({code: 4, message: 'timeout'});
				timeout = true;
				alert('timeout');
			}, 5000);
		}else{
			cb({code:0,message:'no support'});	
		}	
	};

</script>
</body>
</html>

